//
//  HouseTypeViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/10/11.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "HouseTypeViewController.h"
#import "RentVieitor.h"

@interface HouseTypeViewController ()<UITextFieldDelegate>

@end

@implementation HouseTypeViewController {
    
    UITextField *textfile;
    UITextField *tingtextfile;
}

- (void)viewWillAppear:(BOOL)animated {
    
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = self.titleName;
    self.view.backgroundColor = BackgroundColor;
    [self creatLeftView];
    [self creatview];

}

- (void)creatLeftView {
    
    
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(-5, 0, 10, 15);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"箭头左"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftItem;

    // 自定义导航栏左侧按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    rightBtn.frame = CGRectMake(0, 0, 50, 20);
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor colorWithRed:99/255.0 green:99/255.0 blue:99/255.0 alpha:1] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(doneAction) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightItem;

}


- (void)returnTypeBlock:(SelectTypeBlock)block {
    
    self.selecTypeBlock = block;
}

- (void)returnIndexBlock:(SelectTypeBlock)block;
{
    
    self.selectIndexBlock = block;
}

- (void)creatview {
    
    textfile = [[UITextField alloc] initWithFrame:CGRectMake((KWidth-200)/2, 30,50 , 30)];
    textfile.delegate = self;
    textfile.text = self.bed;
    textfile.textColor = [Utils colorConvertFromString:@"#666666"];
    textfile.font = [UIFont systemFontOfSize:13];
    textfile.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:textfile];
    
    CALayer *MlineLayer5 = [CALayer layer];
    MlineLayer5.backgroundColor = [[Utils colorConvertFromString:@"#cfcfcf"] CGColor];
    MlineLayer5.frame = CGRectMake((KWidth-200)/2 ,61, 50,1);
    [self.view.layer addSublayer:MlineLayer5];

    UILabel *selectLabel = [[UILabel alloc] initWithFrame:CGRectMake((KWidth-200)/2+50, 30, 50, 30)];
    selectLabel.text = @"室";
    selectLabel.font = [UIFont systemFontOfSize:15];
    selectLabel.textAlignment = NSTextAlignmentCenter;
    selectLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    [self.view addSubview:selectLabel];
    
    tingtextfile = [[UITextField alloc] initWithFrame:CGRectMake((KWidth-200)/2+100, 30,50 , 30)];
    tingtextfile.delegate = self;
    tingtextfile.text = self.live;
    tingtextfile.textColor = [Utils colorConvertFromString:@"#666666"];
    tingtextfile.font = [UIFont systemFontOfSize:13];
    tingtextfile.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:tingtextfile];
    
    
    CALayer *MlineLayer6 = [CALayer layer];
    MlineLayer6.backgroundColor = [[Utils colorConvertFromString:@"#cfcfcf"] CGColor];
    MlineLayer6.frame = CGRectMake((KWidth-200)/2+100 ,61, 50,1);
    [self.view.layer addSublayer:MlineLayer6];
    
    UILabel *tingselectLabel = [[UILabel alloc] initWithFrame:CGRectMake((KWidth-200)/2+150, 30, 50, 30)];
    tingselectLabel.text = @"厅";
    tingselectLabel.font = [UIFont systemFontOfSize:15];
    tingselectLabel.textAlignment = NSTextAlignmentCenter;
    tingselectLabel.textColor = [Utils colorConvertFromString:@"#101010"];
    [self.view addSubview:tingselectLabel];

    
}

- (void)doneAction {
    
    if (textfile.text == nil || textfile.text.length == 0) {
        
        [APPDELEGATE showPro:@"请输入室房间数量"];
        return;
    }
    
    
    if (tingtextfile.text == nil || tingtextfile.text.length == 0) {
        
        [APPDELEGATE showPro:@"请输入厅房间数量"];
        return;
    }
    
    if (self.selecTypeBlock != nil) {
        self.selecTypeBlock(textfile.text);
    }
    
    if (self.selectIndexBlock != nil) {
        self.selectIndexBlock(tingtextfile.text);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}


@end
